﻿using System;
using System.Linq;
using GdHotel.Data.Interfaces;

namespace GdHotel.Data.Repositories
{
    public class RoomsRepository : IRoomsRepository
    {
        private GdHotelEntities entities = new GdHotelEntities();

        public IQueryable<Room> FindAll()
        {
            return entities.Rooms.AsQueryable();
        }

        public IQueryable<Room> FindAllByLang(Language lang)
        {
            return entities.Rooms.Where(room => room.LanguageId == lang.Id).AsQueryable();
        }

        public Room GetById(Int32 id)
        {
            return entities.Rooms.SingleOrDefault(room => room.Id == id);
        }

        public void Insert(Room room)
        {
            entities.AddToRooms(room);
        }

        public void Delete(Room room)
        {
            entities.Rooms.DeleteObject(room);
        }

        public void Save()
        {
            entities.SaveChanges();
        }

        public void Dispose()
        {
            entities.Dispose();
        }
    }
}
